package tool

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

// Config 定义了配置结构
type Config struct {
	Database struct {
		User     string `yaml:"user"`
		Password string `yaml:"password"`
		Host     string `yaml:"host"`
		Name     string `yaml:"name"`
		Port     string `yaml:"port"`
		LogoMode bool   `yaml:"logo_mode"`
	} `yaml:"database"`
	Server struct {
		AppName string `yaml:"app_name"`
		Port    string `yaml:"port"`
		Mode    string `yaml:"mode"`
		Host    string `yaml:"host"`
	} `yaml:"server"`
	Oss struct {
		Bucket          string `yaml:"bucket"`
		Endpoint        string `yaml:"endpoint"`
		AccessKeyId     string `yaml:"access_key_id"`
		AccessKeySecret string `yaml:"access_key_secret"`
		Domain          string `yaml:"domain"`
	} `yaml:"oss"`
}

var _cfg *Config = nil

func GetConfig() *Config {
	return _cfg
}

func ParseConfig(path string) (*Config, error) {

	cfg, err := ioutil.ReadFile("./config/config.yaml")
	err = yaml.Unmarshal(cfg, &_cfg)
	if err != nil {
		panic(err.Error())
	}
	return _cfg, nil
}
